<?php
$people = $_GET['people'];
$min_time = $_GET['min_time'];
$max_time = $_GET['max_time'];

$longitude = $_GET['longitude'];
$latitude = $_GET['latitude'];


check_numbers(array($people, $min_time, $max_time, $longitude, $latitude));


$result = $db->do_query("SELECT 
	id, 
	name, 
	min_time, 
	max_time, 
	longitude, 
	latitude 
	FROM activities 
	WHERE min_people <= '$people' AND max_people >= '$people' 
	AND min_time <= '$min_time' AND max_time >= '$max_time' 
	ORDER BY location_given*(longitude-'$longitude')*(latitude-'$latitude')
	LIMIT 100");

$activity = $db->random_result($result);

$output = array(
	'id'=>$activity['activity_id'],
	'name'=>$activity['name'],
	'description'=>$activity['description'],
	'latitude'=>$activity['latitude'],
	'longitude'=>$activity['longitude']
);

echo json_encode($output);
?>